const OPEN_MODAL ='scratch-gui/modals/OPEN_MODAL';
const CLOSE_MODAL ='scratch-gui/modals/CLOSE_MODAL';

const MODAL_BACKDROP_LIBRARY = 'backdropLibrary';
const MODAL_My_Projet_LIBRARY = 'myProjectLibrary'; // 我的作品
const MODAL_Yx_Projet_LIBRARY = 'yxProjectLibrary'; // 优秀作品
const MODAL_CAMERA_CAPTURE = 'cameraCapture';
const MODAL_COSTUME_LIBRARY = 'costumeLibrary';
const MODAL_EXTENSION_LIBRARY = 'extensionLibrary';
const MODAL_LOADING_PROJECT ='loadingProject';

const MODAL_SOUND_LIBRARY = 'soundLibrary';
const MODAL_SPRITE_LIBRARY = 'spriteLibrary';
const MODAL_SOUND_RECORDER = 'soundRecorder';
const MODAL_CONNECTION = 'connectionModal';

const initialState = {
    [MODAL_BACKDROP_LIBRARY]: false,
    [MODAL_CAMERA_CAPTURE]: false,
    [MODAL_COSTUME_LIBRARY]: false,
    [MODAL_EXTENSION_LIBRARY]: false,
    [MODAL_LOADING_PROJECT]: false,

    [MODAL_SOUND_LIBRARY]: false,
    [MODAL_SPRITE_LIBRARY]: false,
    [MODAL_SOUND_RECORDER]: false,
    [MODAL_CONNECTION]: false,

    [MODAL_My_Projet_LIBRARY]: false,
    [MODAL_Yx_Projet_LIBRARY]: false
};

const reducer = function (state, action) {
    if (typeof state === 'undefined') state = initialState;
    switch (action.type) {
    case OPEN_MODAL:
        return {...state, [action.modal]: true};
        //return Object.assign({}, state, {[action.modal]: true});
    case CLOSE_MODAL:
        return {...state, [action.modal]: false};
        //return Object.assign({}, state, {[action.modal]: false});
    default:
        return state;
    }
};
const openModal = function (modal) {return {type: OPEN_MODAL, modal: modal};};
const closeModal = function (modal) {return {type: CLOSE_MODAL, modal: modal};};

const openBackdropLibrary = function () {return openModal(MODAL_BACKDROP_LIBRARY);};
const openCameraCapture = function () {return openModal(MODAL_CAMERA_CAPTURE);};
const openCostumeLibrary = function () {return openModal(MODAL_COSTUME_LIBRARY);};
const openExtensionLibrary = function () {return openModal(MODAL_EXTENSION_LIBRARY);};
const openLoadingProject = function () {return openModal(MODAL_LOADING_PROJECT);};

const openSoundLibrary = function () {return openModal(MODAL_SOUND_LIBRARY);};
const openSpriteLibrary = function () {return openModal(MODAL_SPRITE_LIBRARY);};
const openSoundRecorder = function () {return openModal(MODAL_SOUND_RECORDER);};
const openConnectionModal = function () {return openModal(MODAL_CONNECTION);};

const closeBackdropLibrary = function () {return closeModal(MODAL_BACKDROP_LIBRARY);};
const closeCameraCapture = function () {return closeModal(MODAL_CAMERA_CAPTURE);};
const closeCostumeLibrary = function () {return closeModal(MODAL_COSTUME_LIBRARY);};
const closeExtensionLibrary = function () {return closeModal(MODAL_EXTENSION_LIBRARY);};
const closeLoadingProject = function () {return closeModal(MODAL_LOADING_PROJECT);};

const closeSpriteLibrary = function () {return closeModal(MODAL_SPRITE_LIBRARY);};
const closeSoundLibrary = function () {return closeModal(MODAL_SOUND_LIBRARY);};
const closeSoundRecorder = function () {return closeModal(MODAL_SOUND_RECORDER);};
const closeConnectionModal = function () {return closeModal(MODAL_CONNECTION);};

const openMyProjectLibrary = function () {return openModal(MODAL_My_Projet_LIBRARY);};
const closeMyProjectLibrary = function () {return closeModal(MODAL_My_Projet_LIBRARY);};
const openYxProjectLibrary = function () {return openModal(MODAL_Yx_Projet_LIBRARY);};
const closeYxProjectLibrary = function () {return closeModal(MODAL_Yx_Projet_LIBRARY);};

export {
    reducer as default,
    initialState as modalsInitialState,
    openMyProjectLibrary,
    closeMyProjectLibrary,
    openYxProjectLibrary,
    closeYxProjectLibrary,

    openBackdropLibrary,
    openCameraCapture,
    openCostumeLibrary,
    openExtensionLibrary,
    openLoadingProject,
    openSoundLibrary,
    openSpriteLibrary,
    openSoundRecorder,

    openConnectionModal,

    closeBackdropLibrary,
    closeCameraCapture,
    closeCostumeLibrary,
    closeExtensionLibrary,
    closeLoadingProject,
    closeSpriteLibrary,
    closeSoundLibrary,
    closeSoundRecorder,

    closeConnectionModal
};
